﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace L04
{
    class Program
    {
        static void Main(string[] args)
        {
            CzPoint p1 = new CzPoint(1, 2);
            CzPoint p2 = new CzPoint(3, 3);
            CzPoint p3 = new CzPoint(1, 1);
            CzLine l1 = new CzLine(1, 1);
            CzLine l2 = new CzLine(p2, p3);

            if (p1==p2)
                Console.WriteLine("p1,p2相等");
            else Console.WriteLine("p1，p2不相等");
            Console.WriteLine("移动p1到p2后");
            p1.Move(p2.X-p1.X , p2.Y-p1.Y );
            if (p1 == p2)
                Console.WriteLine("p1,p2相等");
            else Console.WriteLine("p1，p2不相等");

            l1.Contains(p1);
            l2.Contains(p1);

            Console.ReadKey();
        }

        public class CzPoint
        {
            private double  x;
            private double  y;

            public double  X { get => x; set => x = value; }
            public double  Y { get => y; set => y = value; }

            public CzPoint (double  x,double  y)
            {
                this.X = x;
                this.Y = y;
            }

            public void Move(double  x,double  y)
            {
                this.X += x;
                this.Y += y;                
            }

            public static bool operator ==(CzPoint c1,CzPoint c2)
            {
                return (c1.X == c2.X) && (c1.Y == c2.Y);
            }

            public static bool operator !=(CzPoint c1, CzPoint c2)
            {
                return (c1.X != c2.X) || (c1.Y != c2.Y);
            }
        }

        //直线方程：y=kx+b
        public class CzLine
        {
            private double a;
            private double b;

            public double A { get => a; set => a = value; }
            public double B { get => b; set => b = value; }

            public CzLine(double a, double b)
            {
                this.a = a;
                this.b = b;
            }

            public CzLine (CzPoint p1,CzPoint p2)
            {
                this.a = (p2.Y - p1.Y) / (p2.X - p1.X);
                this.b = p1.Y - this.a * p1.X;
            }

            public void Move(double x)
            {
                this .b+=x;
            }

            public void  Contains(CzPoint p)
            {
                if (p.Y == a * p.X + b)
                    Console.WriteLine("p点在该直线上");
                else Console.WriteLine("p点不在该直线上");
            }
        }
    }
}
